package typedef

import (
	"encoding/json"
	"errors"
	"github.com/mitchellh/mapstructure"
)

func  MapDecode(input interface{}, output interface{}) error   {
	return mapstructure.Decode(input,output)
}

func JsonDecode(input interface{}, output interface{}) error  {
	jsv, _ := json.Marshal(input)
	return json.Unmarshal(jsv, output)
}

func Decode(input interface{}, output interface{}) error  {
	var err_r error
	if err := MapDecode(input,output);err != nil{
		err_r = errors.New(err.Error())
	} else {
		return nil
	}
	if err := MapDecode(input,output);err != nil{
		err_r = errors.New(err_r.Error() + "\n" +err.Error())
	} else {
		return nil
	}
	return err_r
}
